/**
 * @Description:
 * @Author 卞鹏飞 <228443632@qq.com>
 * @create 05/12/24 AM9:25
 */
import useLayoutStore from '@/store/use-layout-store.ts'
import { storeToRefs } from 'pinia'
import { onMountedOrActivated } from '@shared/hooks/on-mounted-or-activated/index'
// import { onBeforeUnmount, onDeactivated } from 'vue'

/**
 * 页面是否折叠, 自动开启折叠
 * @param {boolean} defaultCollapse 默认进来是否折叠
 * @example
 * ```
 * import usePageCollapse from '@/hooks/use-page-collapse'
 * usePageCollapse()
 * ```
 */
export function usePageCollapse(defaultCollapse = true) {
  const layoutStore = useLayoutStore()

  const { collapse } = storeToRefs(layoutStore)

  onMountedOrActivated(() => {
    collapse.value = defaultCollapse
  })

  // onDeactivated(() => {
  //   collapse.value = !collapse.value
  // })
  //
  // onBeforeUnmount(() => {
  //   collapse.value = !collapse.value
  // })

  return collapse
}
